package top.wardyan.wdev.dbdevassist.control;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.swt.widgets.TableItem;

import top.wardyan.conf.config.SQLite;
import top.wardyan.control.WTable;
import top.wardyan.wdev.dbdevassist.config.DDA;
import top.wardyan.wdev.dbdevassist.model.YTObject;

public class WDevTable extends WTable{
	
	protected static final DDA dda = DDA.getInstance();

	
	public WDevTable(Composite parent, int style, String tablename) {
		super(parent, style, tablename);
	}

	/**
	 * 增加从yt_object中读取的数据
	 * 只加rOwner_ID所有者
	 */
	@Override
	public void show(String tablename, String key) {
		super.show(tablename, key);
		List<YTObject> objs = dda.objectService.list();
		if(objs != null) {
			// 检查有没有这一列的
			boolean founded = false;
			TableColumn[] tcs = self.getColumns();
			for(TableColumn t : tcs) {
				if(t.getText().equals("所有")) {
					founded = true;
					break;
				}
			}
			if(!founded) {
				TableColumn c = new TableColumn(self, SWT.NONE);
				c.setText("所有");
			}
			// 放到MAP中避免每次循环
			Map<String, YTObject> maps = new HashMap<>();
			for(YTObject b : objs) {
				maps.put(b.getXName(), b);
			}
			TableItem[] items = this.getItems();
			if(items != null) {
				top.wardyan.conf.model.YTTableCol colset = SQLite.getInstance().tablecolService.find(self.getShell().getClass().getName(), this.getTablename(), "name");
				if(colset != null) {
					int index = colset.getSIndex();
					for(TableItem it : items) {
						YTObject obj = maps.get(it.getText(index));
						if(obj != null) {
							
						}
						//it.setText(index, );
					}
				}
			}
		}
	}

	
}
